package com.android.zweibo.ui;

import java.util.List;

import weibo4android.Status;

import com.android.zweibo.adapter.WBStatusAdapter;
import com.android.zweibo.bean.Common;
import com.android.zweibo.bean.Task;
import com.android.zweibo.logic.MainService;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

public class HomeActivity extends Activity implements IWeiboActivity {
	private ListView listView;
	private View progressView;
	private View titleView;
   @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		init();
	}
   @Override
	public void init() {
		listView = (ListView) this.findViewById(R.id.listView);
		progressView = this.findViewById(R.id.layout_progress);
		titleView = this.findViewById(R.id.layout_title);
		
		//获取当前用户名称
		TextView userName = (TextView) titleView.findViewById(R.id.title_name);
		userName.setText(MainService.nowUser.getUserName());
		
		newTask();
	}
   
   /**
    * 添加获取微薄时间线任务
    */
	private void newTask() {
        Task task = new Task(Common.GET_FRIEND_TIMELINE, null);
        MainService.newTask(task);
        MainService.addActivity(this);
    }
	
	
	
	@SuppressWarnings("unchecked")
	@Override
	public void refresh(Object... objects) {
		progressView.setVisibility(View.GONE);
		List<Status> status = (List<Status>) objects[0];
		listView.setAdapter(new WBStatusAdapter(status,this));
	}
}
